/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.contactmangerlib;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
/**
 *
 * @author rr185110
 */
@DatabaseTable(tableName="geocode")
public class GeoCode {

    @DatabaseField(generatedId = true)
    private int id;

    @DatabaseField(columnName = "latitude")
    private double latitude;

    @DatabaseField(columnName = "longitude")
    private double longitude;

    private final double earthRadius = 6371000.0; //In Meters

    public GeoCode(){}

    public GeoCode (double latitude, double longitude)
    {
        this.latitude = latitude;
        this.longitude = longitude;
    }

    public double getLatitude()
    {
        return latitude;
    }

    public double getLongitude()
    {
        return longitude;
    }

    public double getApproximateDistanceTo(GeoCode c)
    {
        double ax = Math.abs(c.latitude - latitude)*earthRadius;
        double ay = Math.abs(c.longitude - longitude)*earthRadius;
        
        return Math.sqrt(ax*ax + ay*ay);
    }

}
